﻿function get_Announce_Html(){
  var htmlstr='<table id="Grid_Announce" style="width:auto;height:auto"></table><div id="addAnnouncediv" style="display:none"></div><div id="edtAnnouncediv" style="display:none"></div>';
  return htmlstr;
}
function getadd_Announce_Html(){
  var htmlstr='<div id="AddDlg_Announce" title="添加记录" icon="icon-window" style="padding:5px;background:#fafafa">';
  htmlstr=htmlstr+'<div class="easyui-layout" fit="true">';
  htmlstr=htmlstr+'<div region="center" border="false" style="padding:10px;background:#fff;border:1px solid #ccc;">';
  htmlstr=htmlstr+'<table width="450" border="0" class="dtable" align="center" cellpadding="4" cellspacing="0">';
  htmlstr=htmlstr+'<tr><td width="200"> 关键字 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_AnnounceKey" id="add_AnnounceKey" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 公告标题 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_AnnounceTitle" id="add_AnnounceTitle" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 公告内容 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_AnnounceText" id="add_AnnounceText" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 发布时间 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_UpTime" id="add_UpTime" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 是否显示 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_bitShow" id="add_bitShow" /></td></tr>';htmlstr=htmlstr+'</table></div><div region="south" border="false" style="text-align:right;padding-top:4px;height:30px;line-height:30px;">';
  htmlstr=htmlstr+'<a icon="icon-ok" id="addbt_Announce" href="javascript:void(0)" onclick="Add_Announce()"> 添 加 </a>';
  htmlstr=htmlstr+'</div></div>';
  return htmlstr;
}
function getedt_Announce_Html(){
  var htmlstr='<div id="EditDlg_Announce" title="修改记录" icon="icon-window" style="padding:5px;background:#fafafa">';
  htmlstr=htmlstr+'<div class="easyui-layout" fit="true">';
  htmlstr=htmlstr+'<div region="center" border="false" style="padding:10px;background:#fff;border:1px solid #ccc;">';
  htmlstr=htmlstr+'<table width="450" border="0" class="dtable" align="center" cellpadding="4" cellspacing="0">';
  htmlstr=htmlstr+'<tr><td width="200"> 公告标识 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_AnnounceId" id="edt_AnnounceId" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 关键字 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_AnnounceKey" id="edt_AnnounceKey" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 公告标题 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_AnnounceTitle" id="edt_AnnounceTitle" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 公告内容 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_AnnounceText" id="edt_AnnounceText" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 发布时间 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_UpTime" id="edt_UpTime" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 是否显示 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_bitShow" id="edt_bitShow" /></td></tr>';htmlstr=htmlstr+'</table></div><div region="south" border="false" style="text-align:right;padding-top:4px;height:30px;line-height:30px;">';
  htmlstr=htmlstr+'<a icon="icon-ok" id="edtbt_Announce" href="javascript:void(0)" onclick="Edit_Announce()"> 修 改 </a>';
  htmlstr=htmlstr+'</div></div>';
  return htmlstr;
}
function Add_Announce_Tab(tabname){
  if(!$('#ttab').tabs('exists',tabname)){
	$('#ttab').tabs('add',{
		title:tabname,
		cache:false,
		closable:true,
		content:get_Announce_Html()
	  });
	var gridht = $('body').layout('panel','center').panel('options').height - 58;
	$('#Grid_Announce').datagrid({
	  border:false,
	  nowrap: false,
	  striped: true,
	  collapsible:true,
	  url:'/Data/Announce.ashx',
	  method:'get',
	  height:gridht,
	  queryParams:{type:"0"},
	  fitColumns:true,
	  loadMsg:'正在读取数据,请稍候...',
	  singleSelect:true,
	  columns:[[
		{field:'AnnounceId',checkbox:true},
		{field:'AnnounceKey',title:'关键字',width:80},
		{field:'AnnounceTitle',title:'公告标题',width:80},
		{field:'AnnounceText',title:'公告内容',width:80},
		{field:'UpTime',title:'发布时间',width:80},
		{field:'bitShow',title:'是否显示',width:80}]],
	  pagination:true,
	  rownumbers:true,
	  toolbar:[{
		id:'btn_Announce_add',
		text:'添加',
		iconCls:'icon-add',
		handler:function(){
		  ShowAnnounceAddFrom();}
		},'-',{
		id:'btn_Announce_edit',
		text:'修改',
		iconCls:'icon-edit',
		handler:function(){
		  GetOne_Announce();}
		},'-',{
		id:'btn_Announce_del',
		text:'删除',
		iconCls:'icon-remove',
		handler:function(){
		 Del_Announce();}
	  }],
	  onLoadError:function(er){
		  $.messager.alert('错误','可能无查看权限,无法加载数据!','error');
	  }
	});
  }else{
	$('#ttab').tabs('select',tabname);
  }
}
function ShowAnnounceAddFrom(){
  $('#addAnnouncediv').html(getadd_Announce_Html());
  $('#AddDlg_Announce').window({
	  title: '添加',
	  width: 600,
	  modal: true,
	  shadow: true,
	  closed: true,
	  height: 400
  });
  $('#addbt_Announce').linkbutton({iconCls:"icon-ok"});
  $('#AddDlg_Announce').window('open');
}
function ShowAnnounceEdtFrom(){
  $('#edtAnnouncediv').html(getedt_Announce_Html());
}
function Add_Announce(){
  $.get("/Data/Announce.ashx",{type:2,AnnounceKey:$('#add_AnnounceKey').val(),AnnounceTitle:$('#add_AnnounceTitle').val(),AnnounceText:$('#add_AnnounceText').val(),UpTime:$('#add_UpTime').val(),bitShow:$('#add_bitShow').val()},
  function(data){
    $('#AddDlg_Announce').window('close');
	$('#Grid_Announce').datagrid("reload");
  });
}
function GetOne_Announce(){
  var getid=0;
  var selected = $('#Grid_Announce').datagrid('getSelected');
  if (selected){
    getid=selected.AnnounceId;
	$.getJSON("/Data/Announce.ashx",{type:1,id:getid},
	function(data){
			ShowAnnounceEdtFrom();
			$('#EditDlg_Announce').window({
				title: 'Edit Announce',
				width: 600,
				modal: true,
				shadow: true,
				closed: true,
				height: 300
				});
			$('#EditDlg_Announce').window('open');
			$('#edtbt_Announce').linkbutton({iconCls:"icon-ok"});
						$('#edt_AnnounceId').val(data.model.AnnounceId);
						$('#edt_AnnounceKey').val(data.model.AnnounceKey);
						$('#edt_AnnounceTitle').val(data.model.AnnounceTitle);
						$('#edt_AnnounceText').val(data.model.AnnounceText);
						$('#edt_UpTime').val(data.model.UpTime);
						$('#edt_bitShow').val(data.model.bitShow);
			
      });
	}else{
	        $.messager.show({
				title:'提示',
				msg:'没有选择任何记录.',
				timeout:3000,
				showType:'slide'
			});
	}
}
function Edit_Announce(){
  $.get("/Data/Announce.ashx",{type:4,AnnounceId:$('#edt_AnnounceId').val(),AnnounceKey:$('#edt_AnnounceKey').val(),AnnounceTitle:$('#edt_AnnounceTitle').val(),AnnounceText:$('#edt_AnnounceText').val(),UpTime:$('#edt_UpTime').val(),bitShow:$('#edt_bitShow').val()},
  function(data){
    $('#EditDlg_Announce').window('close');
	$('#Grid_Announce').datagrid("reload");
  }); 
}
function Del_Announce(){
  var getid=0;
  var selected = $('#Grid_Announce').datagrid('getSelected');
  if(!selected){
	        $.messager.show({
				title:'提示',
				msg:'没有选择任何记录.',
				timeout:3000,
				showType:'slide'
			});
			return;
  }
  
  getid=selected.AnnounceId;
  $.messager.confirm('确认删除', '请确认是否进行此操作?', function(r){
	  if(r){
			$.get("/Data/Announce.ashx",{type:3,id:getid},
			function(data){
				$.messager.show({
					title:'提示',
					msg:'已删除数据.',
					timeout:3000,
					showType:'slide'
				});
				$('#Grid_Announce').datagrid("reload");
			}); 
		  }
  }); 
} 
  